﻿Public Class Payment
    Inherits System.Web.UI.Page

    'To set masterpage 
    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        'Check if user is null
        If (Session("user") IsNot Nothing) Then
            'Retrieve userAcc details from session
            Dim userLoggedIn As userAcc = Session("user")
            'Check if user is admin, assign masterpage respectively
            If userLoggedIn.isAdmin Then
                Me.MasterPageFile = "~/MasterPage/Admin.Master"
            Else
                Me.MasterPageFile = "~/MasterPage/User.Master"
            End If
        Else
            'For anonymous users
            Me.MasterPageFile = "~/MasterPage/User.Master"
            'Enable this line to prevent anonymous users from entering this page
            'Response.Redirect("~/Home.aspx")
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack Then
                Dim objPayment As SqlDataSource = SqlDataSourcePayment
                Dim parameter As Parameter = objPayment.SelectParameters(0)
                Dim userLoggedIn As userAcc = Session("user")
                parameter.DefaultValue = userLoggedIn.userID
                lvPayment.DataSourceID = SqlDataSourcePayment.ID
                lvPayment.DataBind()
            End If
            hfPayment.Value = 0

            For Each item As ListViewItem In lvPayment.Items
                Dim cbPayment As CheckBox = item.FindControl("cbPayment")
                If cbPayment.Checked Then
                    Dim costLabel As Label = item.FindControl("costLabel")
                    hfPayment.Value = Convert.ToInt32(hfPayment.Value) + Convert.ToInt32(costLabel.Text)
                End If
                lblTotalCost.Text = hfPayment.Value
            Next
            '  amount.Value = hfPayment.Value.ToString() + ".00"
        Catch

        End Try

    End Sub
    Protected Sub checkedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cbPayment As CheckBox = sender
        Dim costLabel As Label = cbPayment.Parent.FindControl("costLabel")
        Dim cost As Integer = Convert.ToInt32(costLabel.Text)
        If cbPayment.Checked Then
            hfPayment.Value = hfPayment.Value + cost
        Else
            hfPayment.Value = hfPayment.Value - cost
        End If

    End Sub

    Protected Sub InitializeListView(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Protected Sub lvPayment_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles lvPayment.ItemCommand

    End Sub
End Class